package com.whjfxx.terminal.utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

/**
 * Created by b.c on 2022/6/21 11:16
 */
public class DateUtil {

    public static final DateTimeFormatter DTF_YYYYMMDDHHMMSS = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

    /**
     * 时间格式化
     * @param dateStr
     * @return
     */
    public static LocalDateTime parse_yyyyMMddHHmmss(String dateStr) {
        return LocalDateTime.parse(dateStr, DTF_YYYYMMDDHHMMSS);
    }

    /**
     * 时间转字符串
     * @param expiryTime
     * @return
     */
    public static String formate_yyyyMMddHHmmss(LocalDateTime expiryTime) {
        if (Objects.isNull(expiryTime)) {
            return null;
        }
        return expiryTime.format(DTF_YYYYMMDDHHMMSS);
    }

    /**
     *
     * @return
     */
    public static LocalDateTime today() {
        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.NOON);
        return localDateTime;
    }

    /**
     * 校验是
     * @param expiryTime
     * @return
     */
    public static boolean beforeNow(LocalDateTime expiryTime) {
        LocalDateTime today = LocalDateTime.now();
        return expiryTime.compareTo(today) < 0;
    }

}
